#include "uart.h"

char buffer[32];

void uart_putchar(const char ch) {
  while (0 == ((*WRITE_VALID) & 1))
    ;
  *WRITE_DATA_ADDR = ch;
}

void uart_puts(const char *str) {
  for (int k = 0; str[k]; ++k)
    uart_putchar(str[k]);
}

char uart_getchar() {
  char ch = 0;
  while (0 == ((*READ_VALID) & 1))
		;
  ch = *READ_DATA_ADDR;
  return ch;
}

void uart_gets() {
	int cnt = 0;
	while(1) {
		char ch = uart_getchar();
		buffer[cnt++] = ch;
		if(ch == '\n') {
			buffer[cnt] = '\0';
			break;
		}
	}
}
